package springboot.service.impl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client;
import springboot.bean.AgvTaskReturn;
import springboot.kernel.KernelTools;
import springboot.service.AgvService;
import springboot.wstool.WSTools;

import javax.jws.WebParam;
import javax.jws.WebService;
import java.util.Date;

@Slf4j
@WebService(serviceName = "AgvService", // 与接口中指定的name一致
        targetNamespace = "http://service.springboot/", // 与接口中的命名空间一致,一般是接口的包名倒
        endpointInterface = "springboot.service.AgvService"// 接口地址
)
public class AgvServiceImpl implements AgvService {
    KernelTools kernelTools=null;
    AgvTaskReturn agvTaskReturn=null;
    WSTools wsTools=new WSTools();
    @Override
    public String sendAgvTask(@WebParam(name = "taskNo")String taskNo,
                           @WebParam(name = "source")String source,
                           @WebParam(name = "destination")String destination,
                           @WebParam(name = "status")String status,
                           @WebParam(name = "agvId")String agvId,
                           @WebParam(name = "creatData")Date creatData,
                           @WebParam(name = "isClosed")String isClosed) throws Exception {
        kernelTools = new KernelTools();

        if (status != null) {
            if (status.equals("10")) {
                if (taskNo != null && source != null && destination != null) {
                    kernelTools.CreateOrderOneStation(source, destination, taskNo);
                    /*此处任务状态改为20,表示已接收*/
                    /*Object[] objects = new Object[0];
                    Client client=wsTools.getClient();
                    objects=client.invoke("",taskNo,"20","0001",new Date(),"0");
                    System.out.println("返回数据:" + objects[0]);*/
                    log.info("任务状态改为20,表示已接收");
                    agvTaskReturn=new AgvTaskReturn("success","task is created");
                    String result=JSON.toJSONString(agvTaskReturn);
                    return result;
                }
                agvTaskReturn=new AgvTaskReturn("failed","taskNo|source|destination is not null");
                String result=JSON.toJSONString(agvTaskReturn);
                return result;
            }
            agvTaskReturn=new AgvTaskReturn("failed","status is not equal 10");
            String result=JSON.toJSONString(agvTaskReturn);
            return result;
        }
        agvTaskReturn=new AgvTaskReturn("failed","status is null");
        String result=JSON.toJSONString(agvTaskReturn);
        return result;
    }

}
